/* $Id: UtilityFacadeImpl 
 * Copyright (C) 2011, Trakhees
 *  
 *  History
 *
 * Date  			Author 					Remarks
 * -------------------------------------------------------------
 * May 05, 2011 	Neha_Chauhan 	        Created
 *
 */
package ae.pcfc.etks.online.common.facade.provider;

import java.util.ArrayList;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import ae.pcfc.etks.online.common.domain.TTscCity;
import ae.pcfc.etks.online.common.domain.TTscClientRole;
import ae.pcfc.etks.online.common.domain.TTscCountry;
import ae.pcfc.etks.online.common.domain.TTscDepartments;
import ae.pcfc.etks.online.common.domain.TTscEmirate;
import ae.pcfc.etks.online.common.domain.TTscEmirateCity;
import ae.pcfc.etks.online.common.domain.TTscLicIssuingAuthority;
import ae.pcfc.etks.online.common.domain.TTscLicType;
import ae.pcfc.etks.online.common.domain.TTscNametitle;
import ae.pcfc.etks.online.common.domain.TTscVisaType;
import ae.pcfc.etks.online.common.domain.manager.UserRoleDomainObjectManager;
import ae.pcfc.etks.online.common.domain.manager.UtilityDomainObjectManager;
import ae.pcfc.etks.online.common.facade.UtilityFacade;
import ae.pcfc.etks.online.common.vo.CityVO;
import ae.pcfc.etks.online.common.vo.ClientRoleVO;
import ae.pcfc.etks.online.common.vo.CountryVO;
import ae.pcfc.etks.online.common.vo.DepartmentVO;
import ae.pcfc.etks.online.common.vo.EmirateCityVO;
import ae.pcfc.etks.online.common.vo.EmirateVO;
import ae.pcfc.etks.online.common.vo.LicIssueAuthVO;
import ae.pcfc.etks.online.common.vo.LicTypeVO;
import ae.pcfc.etks.online.common.vo.NameTitleVO;
import ae.pcfc.etks.online.common.vo.VisaTypeVO;

public class UtilityFacadeImpl extends BaseFacade implements UtilityFacade {
    	/*
	 * Here we coordinate between the all interacting business domain objects
	 * (BO), transactions are maintained here. use case business validation are
	 * maintained here (that requires DB checks or retrieving data from DB)
	 */
	private UtilityDomainObjectManager utilityDomainObjectManager;
	private UserRoleDomainObjectManager userRoleDomainObjectManager;

	/**
	 * getUtilityDomainObjectManager
	 * 
	 * @return UtilityDomainObjectManager
	 */
	/**
	 * getUtilityDomainObjectManager
	 * 
	 * @return
	 * UtilityDomainObjectManager
	 */
	public UtilityDomainObjectManager getUtilityDomainObjectManager() {
		return utilityDomainObjectManager;
	}

	/**
	 * setUtilityDomainObjectManager
	 * 
	 * @param utilityDomainObjectManager
	 * void
	 */
	public void setUtilityDomainObjectManager(
			UtilityDomainObjectManager utilityDomainObjectManager) {
		this.utilityDomainObjectManager = utilityDomainObjectManager;
	}
	
	/**
	 * setUserRoleDomainObjectManager
	 * 
	 * @param userRoleDomainObjectManager
	 * void
	 */
	public void setUserRoleDomainObjectManager(UserRoleDomainObjectManager userRoleDomainObjectManager) {
		this.userRoleDomainObjectManager = userRoleDomainObjectManager;
	}

	/**
	 * getCountryList
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getCountryList(java.lang.String)
	 * 
	 */
	@Transactional(readOnly = true)
	public List<CountryVO> getCountryList(String locale) {

		List<TTscCountry> countries = utilityDomainObjectManager
				.getCountryList(locale);

		List<CountryVO> countryVOs = new ArrayList<CountryVO>();

		CountryVO countryVO;

		for (TTscCountry country : countries) {
			countryVO = new CountryVO();
			if (null != country)
				getMapper().map(country, countryVO);
			countryVOs.add(countryVO);
		}
		return countryVOs;
	}

	/**
	 * getCityListByCountryCode
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getCityListByCountryCode(java.lang.String,
	 *      java.lang.String)
	 * 
	 */
	/**
	 * getCityListByCountryCode
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getCityListByCountryCode(java.lang.String, java.lang.String)
	 * 
	 */
	@Transactional(readOnly = true)
	public List<CityVO> getCityListByCountryCode(String countryCode,
			String locale) {

		List<TTscCity> cities = utilityDomainObjectManager
				.getCityListByCountryCode(countryCode, locale);

		List<CityVO> cityVOs = new ArrayList<CityVO>();

		CityVO cityVO;

		for (TTscCity city : cities) {
			cityVO = new CityVO();
			if (null != city)
				getMapper().map(city, cityVO);
			cityVOs.add(cityVO);
		}
		return cityVOs;
	}

	/**
	 * getLicIssuingAuth
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getLicIssuingAuth()
	 * 
	 */
	/**
	 * getLicIssuingAuth
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getLicIssuingAuth()
	 * 
	 */
	@Transactional(readOnly = true)
	public List<LicIssueAuthVO> getLicIssuingAuth() {

		List<TTscLicIssuingAuthority> authorities = utilityDomainObjectManager
				.getLicIssuingAuth();

		List<LicIssueAuthVO> authVOs = new ArrayList<LicIssueAuthVO>();

		LicIssueAuthVO authVO;

		for (TTscLicIssuingAuthority authority : authorities) {
			authVO = new LicIssueAuthVO();
			if (null != authority)
				getMapper().map(authority, authVO);
			authVOs.add(authVO);
		}
		return authVOs;
	}

	/**
	 * getClientRoleList
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getClientRoleList(java.lang.String,
	 *      boolean)
	 * 
	 */
	/**
	 * getClientRoleList
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getClientRoleList(java.lang.String, boolean)
	 * 
	 */
	@Transactional(readOnly = true)
	public List<ClientRoleVO> getClientRoleList(String clientCategory,
			boolean bHideDefault) {

		List<TTscClientRole> clientRoles = utilityDomainObjectManager
				.getClientRoleList(clientCategory, bHideDefault);

		if (clientRoles != null && clientRoles.size() > 0) {
			List<ClientRoleVO> clientRoleVOList = new ArrayList<ClientRoleVO>();
			ClientRoleVO clientRoleVO;

			for (TTscClientRole clientRole : clientRoles) {
				clientRoleVO = new ClientRoleVO();
				if (null != clientRole)
					getMapper().map(clientRole, clientRoleVO);
				clientRoleVOList.add(clientRoleVO);
			}
			return clientRoleVOList;
		}
		return null;
	}

	/**
	 * getLicType
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getLicType()
	 * 
	 */
	/**
	 * getLicType
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getLicType()
	 * 
	 */
	@Transactional(readOnly = true)
	public List<LicTypeVO> getLicType() {

		List<TTscLicType> lictypes = utilityDomainObjectManager.getLicType();

		List<LicTypeVO> lictypeVOs = new ArrayList<LicTypeVO>();

		LicTypeVO lictypeVO;

		for (TTscLicType lictype : lictypes) {
			lictypeVO = new LicTypeVO();
			if (null != lictype)
				getMapper().map(lictype, lictypeVO);
			lictypeVOs.add(lictypeVO);
		}
		return lictypeVOs;
	}

	/**
	 * getNameTitle
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getNameTitle()
	 * 
	 */
	/**
	 * getNameTitle
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getNameTitle()
	 * 
	 */
	@Transactional(readOnly = true)
	public List<NameTitleVO> getNameTitle() {

		List<TTscNametitle> nametitles = utilityDomainObjectManager
				.getNameTitle();

		List<NameTitleVO> nametitleVOs = new ArrayList<NameTitleVO>();

		NameTitleVO nametitleVO;

		for (TTscNametitle nametitle : nametitles) {
			nametitleVO = new NameTitleVO();
			if (null != nametitle)
				getMapper().map(nametitle, nametitleVO);
			nametitleVOs.add(nametitleVO);
		}
		return nametitleVOs;
	}

	/**
	 * getVisaType
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getVisaType()
	 * 
	 */
	/**
	 * getVisaType
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getVisaType()
	 * 
	 */
	@Transactional(readOnly = true)
	public List<VisaTypeVO> getVisaType() {

		List<TTscVisaType> visatypes = utilityDomainObjectManager.getVisaType();

		List<VisaTypeVO> visatypeVOs = new ArrayList<VisaTypeVO>();

		VisaTypeVO visatypeVO;

		for (TTscVisaType visatype : visatypes) {
			visatypeVO = new VisaTypeVO();
			if (null != visatype)
				getMapper().map(visatype, visatypeVO);
			visatypeVOs.add(visatypeVO);
		}
		return visatypeVOs;
	}

	/**
	 * getDepartments
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getDepartments()
	 * 
	 */
	/**
	 * getDepartments
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getDepartments()
	 * 
	 */
	@Transactional(readOnly = true)
	public List<DepartmentVO> getDepartments() {

		List<TTscDepartments> departments = utilityDomainObjectManager
				.getDepartments();

		List<DepartmentVO> deptypeVOs = new ArrayList<DepartmentVO>();

		DepartmentVO deptypeVO;

		for (TTscDepartments department : departments) {
			deptypeVO = new DepartmentVO();
			if (null != department)
				getMapper().map(department, deptypeVO);
			deptypeVOs.add(deptypeVO);
		}
		return deptypeVOs;
	}

	/**
	 * getUserSecurityRole
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getUserSecurityRole(java.lang.String)
	 * 
	 */
	/**
	 * getUserSecurityRole
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getUserSecurityRole(java.lang.String)
	 * 
	 */
	@Transactional(readOnly = true)
	public List<String> getUserSecurityRole(String userName) {

		return this.userRoleDomainObjectManager.getUserSecurityRole(userName);
	}

	/**
	 * getLicIssuingAuthorityByCode
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getLicIssuingAuthorityByCode(java.lang.String)
	 * 
	 */
	/**
	 * getLicIssuingAuthorityByCode
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getLicIssuingAuthorityByCode(java.lang.String)
	 * 
	 */
	@Transactional(readOnly = true)
	public LicIssueAuthVO getLicIssuingAuthorityByCode(String licIACode) {

		TTscLicIssuingAuthority licIssuingAuthority = this.utilityDomainObjectManager
				.getLicIssuingAuthorityByCode(licIACode);
		LicIssueAuthVO licIssueAuthVO = null;

		if (licIssuingAuthority != null) {
			licIssueAuthVO = new LicIssueAuthVO();
			getMapper().map(licIssuingAuthority, licIssueAuthVO);
		}

		return licIssueAuthVO;
	}

	/**
	 * getAllLicIssuingAuth
	 * 
	 * @see ae.pcfc.etks.online.common.facade.UtilityFacade#getAllLicIssuingAuth()
	 * 
	 */
	@Transactional(readOnly = true)
	public List<LicIssueAuthVO> getAllLicIssuingAuth() {
		List<TTscLicIssuingAuthority> authorities = utilityDomainObjectManager
				.getAllLicIssuingAuth();

		List<LicIssueAuthVO> authVOs = new ArrayList<LicIssueAuthVO>();

		LicIssueAuthVO authVO;

		for (TTscLicIssuingAuthority authority : authorities) {
			authVO = new LicIssueAuthVO();
			if (null != authority)
				getMapper().map(authority, authVO);
			authVOs.add(authVO);
		}
		return authVOs;
	}
	
	@Transactional(readOnly = true)
	public List<EmirateVO> getEmirates(String locale) {

		List<TTscEmirate> emirates = utilityDomainObjectManager
				.getEmirates(locale);
		List<EmirateVO> emirateVOs = new ArrayList<EmirateVO>();

		EmirateVO emirateVO;

		for (TTscEmirate emirate : emirates) {
			emirateVO = new EmirateVO();

			if (emirate != null) {
				getMapper().map(emirate, emirateVO);
				emirateVOs.add(emirateVO);
			}

		}

		return emirateVOs;
	}
	
	@Transactional(readOnly = true)
	public List<EmirateCityVO> getEmirateCityByEmirateCode(String emirateCode,
			String locale) {

		List<TTscEmirateCity> emirateCities = utilityDomainObjectManager
				.getEmirateCityByEmirateCode(emirateCode, locale);
		List<EmirateCityVO> emirateCityVOs = new ArrayList<EmirateCityVO>();

		EmirateCityVO emirateCityVO;

		for (TTscEmirateCity emirateCity : emirateCities) {

			emirateCityVO = new EmirateCityVO();
			if (emirateCity != null) {
				getMapper().map(emirateCity, emirateCityVO);
				
				emirateCityVOs.add(emirateCityVO);
			}
		}

		return emirateCityVOs;
	}
}
